package com.vnie.mina.codec;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

import com.vnie.mina.message.BaseMessage;


public class ByteRequestEncoder extends ProtocolEncoderAdapter {

	public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {  
		 	try {
		 		BaseMessage request = (BaseMessage) message;  
		 		byte[] byteArr = request.getEntity();
		        IoBuffer buffer = IoBuffer.allocate(byteArr.length, false);  
		        buffer.put(byteArr);
		        buffer.flip();  
		        out.write(buffer);
			} catch (Exception e) {
				System.out.println(e.toString());
			}  
	    }  
	  
	    public void dispose(IoSession session) throws Exception {  
	        // nothing to dispose  
	    } 

}
